Component({
  /**
   * 组件的属性列表
   */
  properties: {
    setting: {
      type: Object,
      value: null
    },
    // 是否显示搜索框
    show_search: {
      type: Number,
      value: 1
    },
    // 是否开启下滑显示
    is_opacity: {
      type: Number,
      value: 1
    },
    headheight: {
      type: Number,
      value: 10
    },
    text_color: {
      type: String,
      value: null
    },
    text_background: {
      type: String,
      value: null
    },
    // diy页面判断是否顶部自吸
    template: {
      type: Array,
      value: null
    },
    // 首页自定义分类是否顶部自吸
    update_cat: {
      type: Array,
      value: null
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    menuButtonBoundingClientRect:{},
    systemInfo:{},
    is_show_cat: 0,
    cat_list: null
    //opacity : 0
  },

  ready: function () {
    var that = this;
    this.setData({
      store: wx.getStorageSync('store')
    })
    if (this.properties.template) {
      var template = this.data.template;
      template.forEach(element => {
        if (element.type=='cat_goods') {
          that.setData({
            cat_list: element.param.list,
          })
        }
      });
      
    }
    if (this.properties.update_cat) {
      
    }
  },
  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show: function () {
      var that = this
      wx.getSystemInfo({
        success: function(res) {
          that.setData({
            systemInfo: res,
            menuButtonBoundingClientRect: wx.getMenuButtonBoundingClientRect()
          })
          console.log(that.data.systemInfo)
        },
      })
    },
    hide: function () { },
    resize: function () { },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    setOpacity:function(scrollTop,maxTop){
      let opacity = 0
      if(scrollTop<=maxTop){
        opacity = scrollTop/maxTop
      }else{
        opacity = 1
      }
      this.setData({
        opacity:opacity
      })
    },
    back2home:function() {
      wx.navigateBack({
        delta: 1,
      })
    },
    catTop:function(scrollTop,maxTop){
      let opacity = 0
      if(scrollTop<=maxTop && this.data.is_show_cat == 0){
        this.setData({
          is_show_cat:1
        })
      }else {
        this.setData({
          is_show_cat:0
        })
      }
      
    },
  }
})
